@extends('public.layouts')
@section('style')
    <meta name="_token" content="{{ csrf_token() }}"/>
    <style>
        .ip-sell-th {
            text-align: center;
        }

        .ip-sell-td {
            text-align: center;
        }

        .small-box {
            height: 120px;
        !important;
        }

        .sell-title {
            color: white;
            margin-top: 15%;
        }
    </style>
    <link rel="stylesheet" href="{{asset('admin_assets/css/bootstrap-datetimepicker.min.css')}}">
    <link rel="stylesheet" href="{{url('admin_assets/css/ip.css')}}">
    <link rel="stylesheet" href="{{url('css/search.css')}}">
@stop
@section('content')
    <div class="content-wrapper" style="background-color: white">
        <section class="content">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="box box-info"
                         style="padding-top: 0px;margin-top: 0px;border-top: 0px;border-bottom: solid 1px #0080ff;">
                        <div class="box-body" style="">
                            <div class="row">
                                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="margin-top: 1%">
                                    <a href="#" title="返回首页" style="float: left"><i class="fa fa-home fa-2x"
                                                                                    style="width: 100%;color: #009aff">
                                        </i></a>
                                    <a href="#"><span
                                                style="font-size: 20px;float: left;color: #009aff">&nbsp;IP交易出售</span></a>
                                    <div class="clear"></div>
                                </div>
                                <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12 col-lg-offset-6 col-md-offset-4 btn-div">
                                    <button type="button" class="btn btn-info div-btn" data-toggle="modal"
                                            data-target="#modal-addIpSell"
                                            style="background: #009aff;float: right;margin-left: 1%;margin-top: 1%">增加出售
                                    </button>
                                    {{--<form action="{{url('user/ip/IpSellSearch')}}" method="post" enctype="multipart/form-data" class="search">--}}
                                        {{--{{csrf_field()}}--}}
                                        {{--<button class="fa fa-search fa-lg"></button>--}}
                                        {{--<input type="search" class="search" id="search-input" name="search">--}}
                                    {{--</form>--}}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            @include('public/alert')
            <div class="row" style="margin-left: 10px">
                <form class="form-inline" action="{{url('user/ip/IpSellCertain')}}" name="form1" method="post"
                      enctype="multipart/form-data">
                    {{csrf_field()}}
                    <label for="exampleInputName2">类型</label>
                    <select name="first_type" id="province" class="form-control" onchange="changeSelect(this.selectedIndex)"></select>
                    <label for="exampleInputName2">类别</label>
                    <select name="second_type" id="city" class="form-control"></select>
                    <div class="form-group">
                        <label for="exampleInputEmail2">名称</label>
                        <input type="text" class="form-control" name="name" id="exampleInputEmail2" placeholder="名称">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputName2">发布时间</label>
                        <input type="date" name="created_at" class="form-control" id="exampleInputName2" >
                    </div>
                    <label for="exampleInputName2">进度</label>
                    <select name="progress" class="form-control">{{--1卖方同意，2买方同意，3合同签订，4手续办理，5办理成功，6转让凭证寄送，7等待处理，8无法购买--}}
                        <option value="">不填</option>
                        <option value="1">卖方同意</option>
                        <option value="2">买方同意</option>
                        <option value="3">合同签订</option>
                        <option value="4">手续办理</option>
                        <option value="5">办理成功</option>
                        <option value="6">转让凭证寄送</option>
                        <option value="7">等待处理</option>
                        <option value="8">无法购买</option>
                    </select>
                    <button type="submit" class="btn btn-default">搜索</button>
                </form>
            </div>
            <div class="row" style="margin-top: 2%">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th class="ip-sell-th">序号</th>
                                <th class="ip-sell-th">类型</th>
                                <th class="ip-sell-th">类别</th>
                                <th class="ip-sell-th">编号</th>
                                <th class="ip-sell-th">名称</th>
                                <th class="ip-sell-th">是否授权</th>
                                <th class="ip-sell-th">期望成交价</th>
                                <th class="ip-sell-th">最低成交价</th>
                                <th class="ip-sell-th">发布日期</th>
                                <th class="ip-sell-th">进度</th>
                                <th class="ip-sell-th">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @if($product->isEmpty())
                                <tr>
                                    <td class="ip-sell-th" colspan="11"><h3 align="center">暂无数据</h3></td>
                                </tr>
                            @else
                                @foreach($product as $k =>$v)
                                    <tr>
                                        <td class="ip-sell-td" style="vertical-align: middle">{{$k+1}}</td>
                                        <td class="ip-sell-td"
                                            style="vertical-align: middle">{{$v['FirstType']['name']}}</td>
                                        <td class="ip-sell-td"
                                            style="vertical-align: middle">{{$v['SecondType']['name']}}</td>
                                        <td class="ip-sell-td"
                                            style="vertical-align: middle">
                                            @if(!empty($v['num']))
                                                {{$v['num']}}
                                                @endif

                                        </td>
                                        <td class="ip-sell-td"
                                            style="vertical-align: middle">{{$v['product_name']}}</td>
                                        <td class="ip-sell-td" style="vertical-align: middle">
                                            @if($v['is_authorization']==1)
                                                授权
                                            @else
                                                未授权
                                            @endif
                                        </td>
                                        <td class="ip-sell-td" style="vertical-align: middle">
                                            ¥{{$v['ideal_price']}}</td>
                                        <td class="ip-sell-td" style="vertical-align: middle">
                                            ¥{{$v['min_price']}}</td>
                                        <td class="ip-sell-td"
                                            style="vertical-align: middle">{{date("Y-m-d",strtotime($v['created_at']))}}</td>
                                        <td class="ip-sell-td"
                                            style="vertical-align: middle">{{config('config.buyIP_progress')[$v['progress']-1]}}</td>
                                        <td class="ip-sell-td" style="vertical-align: middle">
                                            <a href="#" data-toggle="modal" class="p"
                                               ip_id="{{$v['id']}}"
                                               name="{{$v['product_name']}}"
                                               num="{{$v['num']}}"
                                               is_authorization="{{$v['is_authorization']}}"
                                               ideal_price="{{$v['ideal_price']}}"
                                               min_price="{{$v['min_price']}}"
                                               is_own="{{$v['is_own']}}"
                                               data-target="#edit-IP-sellModal">修改&nbsp;</a>
                                            <a href="{{url('user/ip/delIpSell',['id'=>$v['id']])}}"
                                               onclick="return confirm('确定要删除吗？')">&nbsp;删除</a>
                                        </td>
                                    </tr>
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </section>
    </div>
    @include('public.addIpSellModal')
    @include('public.editIPSellModal')
@stop
@section('javascript')
    <script src="{{asset('admin_assets/js/bootstrap-datetimepicker.min.js')}}"></script>
    <script src="{{asset('js/ip.js')}}"></script>
    <script>
        $(".p").click(function () {
            var is_authorization = $(this).attr('is_authorization');
            var is_own = $(this).attr('is_own');
            var name = $(this).attr('name');
            var num = $(this).attr('num');
            $("#hide_id").val($(this).attr('ip_id'));
            $("#hide_is_own").val($(this).attr('is_own'));
            $("#edit_expect_price").val($(this).attr('ideal_price'));
            $("#edit_lowest_price").val($(this).attr('min_price'));
            $("#edit_is_authorize").find("option[value='" + is_authorization + "']").attr("selected", true);
            if (is_own == 1) {
                $("#edit_name").val($(this).attr('name'));
                $("#edit_name").attr('disabled', true);
                $("#edit_num").val($(this).attr('num'));
                $("#edit_num").attr('disabled', true);
            } else if (is_own == 0) {
                $("#edit_name").val($(this).attr('name'));
                $("#edit_name").attr('disabled', false);
                $("#edit_num").val($(this).attr('num'));
                $("#edit_num").attr('disabled', false);
            }
        });
        $(".form_datetime").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            autoclose: true,
            todayBtn: true,
            minuteStep: 10,
            language: "en"
        });

        function getType(e) {
            $.ajax({
                url: '{{url('user/ip/getSecondType')}}',
                type: 'post',
                dataType: 'json',
                data: {
                    'id': e.val()
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {
                    console.log(data);
                    var type = $('#second_type');
                    type.empty();
                    var size = data.length;
                    if (size <= 0) {
                        type.append('<option value="-1">类别</option>');
                    } else {
                        for (var i = 0; i < data.length; i++) {
                            var item = data[i];
                            type.append('<option value="' + item['id'] + '">' + item['name'] + '</option>');
                        }
                    }
                }
            })
        }
        /*下面是类型与类别的二级联动*/
        var arr_province = ["不填","专利","商标","版权","项目"];
        var arr_city = [
            ["不填"],
            ["发明","实用新型","外观设计"],
            ['中文','英文','图形', '组合'],
            ['美术作品', '软件著作'],
            ['创新', '高企', '高转', '小巨人', '双软', '贯标']
        ];
        //网页加载完成，初始化菜单
        window.onload = init;//传入函数地址
        function init(){
            //首先获取对象
            var province = document.form1.province;
            var city = document.form1.city;

            //指定省份中<option>标记的个数
            province.length = arr_province.length;

            //循环将数组中的数据写入<option>标记中
            for(var i=0;i<arr_province.length;i++){
                province.options[i].text = arr_province[i];
                province.options[i].value = arr_province[i];
            }

            //修改省份列表的默认选择项
            var index = 0;
            province.selectedIndex = index;

            //指定城市中<option>标记的个数
            city.length = arr_city[index].length;

            //循环将数组中的数据写入<option>标记中
            for (var j = 0; j<arr_city[index].length;j++) {
                city.options[j].text = arr_city[index][j];
                city.options[j].value = arr_city[index][j];
            }

        }

        function  changeSelect(index){
            //选择对象
            var city = document.form1.city;
            //修改省份列表的选择项
            province.selectedIndex = index;

            //指定城市中<option>标记的个数
            city.length = arr_city[index].length;

            //循环将数组中的数据写入<option>标记中
            for (var j = 0; j<arr_city[index].length;j++) {
                city.options[j].text = arr_city[index][j];
                city.options[j].value = arr_city[index][j];
            }
        }

    </script>
@stop
